<?php
/**
 * Created by novebeta.
 * Date: 12/4/12
 * Time: 7:36 PM
 */
Yii::import('ext.portlet.XPortlet');
class EventSchedule extends XPortlet
{
    protected function renderContent()
    {
        $year = date("Y");
        $year_from = $year - 1;
        $year_after = $year + 1;
        $isIndo = lang() == "id";
        $this->title = $isIndo ? "Jadwal Acara" : "Event Schedule";
        $db = app()->getDb();
        $result = $db->createCommand("select nama,name_,tgl_mulai,DATEDIFF(tgl_selesai,tgl_mulai) as diff
        from {{agenda}} where `status` and tgl_mulai > '$year_from-01-01' and tgl_selesai < '$year_after-12-31'
        ")->queryAll();
        $inside = "";
        foreach($result as $key => $agenda){
            for($i = 0;$i <= $agenda['diff'];$i++){
                $date = new DateTime($agenda['tgl_mulai']);
                $date->modify("+$i day");
                $inside .= "[".$date->format('m,d,Y').",'".$agenda[$isIndo?'nama':'name_']."'],";
            }
        }
        $ui = "[$inside]";
        $this->render('eventSchedule', array('ui'=>$ui));
    }
}
